home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / OWLCTL.ZIP;1 / TSTCTL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-22  |  21.9 KB  |  567 lines

  1. /* KNB Version 2.0 */
  2. //code gen'd by Case:W 4.0
  3. #define EXTERN
  4. #include "TSTCTL.hpp"
  5.  
  6. #include <commdlg.h>
  7.  
  8. #include <uty25001.h>
  9. #include <uty3dowl.h>
  10.  
  11.  
  12. _CLASSDEF(TMyAppObject);
  13. class _EXPORT TMyAppObject : public TApplication
  14. {
  15.  
  16. public:
  17.        /* Application object constructor.                                */
  18.        TMyAppObject(
  19.              LPSTR AppName,
  20.              HINSTANCE hCurr,
  21.              HINSTANCE hPrev,
  22.              LPSTR CmdLine,
  23.              int   CmdShow) :TApplication(AppName,hCurr,hPrev,CmdLine,CmdShow){};
  24.  
  25.        virtual void InitMainWindow();
  26.        virtual void InitApplication()
  27.          {
  28.             UtyCtlMakeLink();
  29.          };
  30.        BOOL ProcessMDIAccels(LPMSG) { return FALSE; };
  31.      
  32. };
  33.  
  34. /*************************************************************************/
  35. /*                                                                       */
  36. /* Class Definition For Window Object tstctlTWindow                      */
  37. /*                                                                       */
  38. /*************************************************************************/
  39.  
  40. _CLASSDEF(tstctlTWindow);
  41.  
  42. class _EXPORT tstctlTWindow : public TWindow
  43. {
  44. private:
  45.    PTListBox pList;
  46. public:
  47.       /* Derived window constructor */
  48.       tstctlTWindow(PTWindowsObject AParent, LPSTR ATitle);
  49.       void SetupWindow();
  50.       virtual void GetWindowClass(WNDCLASS _FAR &AWndClass);
  51.       virtual Pchar nameOf() const { return "tstctlTWindow"; }
  52.       virtual LPSTR GetClassName() { return (LPSTR)"tstctlTWindow" ; };
  53.       virtual void CMMethod_IDM_DIALOG(RTMessage Msg) = 
  54.              [CM_FIRST + IDM_DIALOG];
  55.       void CwCreateClientControls(PTWindowsObject);
  56.       void WMCtlColor(RTMessage msg)
  57.        = [WM_FIRST + WM_CTLCOLOR];
  58. };
  59.  
  60.  
  61.  
  62. /************************************************************************/
  63. /*                                                                      */
  64. /* Class definition for testTDialog Object.                              */
  65. /*                                                                      */
  66. /************************************************************************/
  67.  
  68. _CLASSDEF(testTDialog);
  69.  
  70. class _EXPORT testTDialog : public TDialog
  71. {
  72. private:
  73.  
  74. public:
  75.      testTDialog(PTWindowsObject Parent, int ResID);
  76.      virtual void SetupWindow();
  77.      virtual Pchar nameOf() const { return "testTDialog"; }
  78.      void Ok(RTMessage Msg) = 
  79.         [ID_FIRST + IDOK];
  80.      void FileOpen(RTMessage Msg) =
  81.         [ID_FIRST + 131];
  82. };
  83.  
  84.  
  85. /*************************************************************************/
  86. /*                                                                       */
  87. /* WinMain, the main of the OWL program                                  */
  88. /*                                                                       */
  89. /* In an OWL program, WinMain does very little actual work.  The appli-  */
  90. /* cation object takes responsibility for most of the tasks formerly     */
  91. /* carried out by WinMain.                                               */
  92. /* WinMain is one of the few functions in an OWL program that had to be  */
  93. /* modified for STRICT compliance.  Instance handles (hCurrent and hPrev)*/
  94. /* were of type HANDLE in Windows 3.0, but are now of type HINSTANCE.    */
  95. /*                                                                       */
  96. /*************************************************************************/
  97.                                                                          
  98.    int PASCAL WinMain(HINSTANCE hCurrent,
  99.                       HINSTANCE hPrev,                    
  100.                       LPSTR  Cmdline, 
  101.                       int CmdShow)
  102.    {
  103.  
  104.      /* Instantiate the application object derived from OWL TApplication
  105.         object                                                           */
  106.      TMyAppObject MyApplication("Test New Controls",
  107.                                  hCurrent,
  108.                                  hPrev,
  109.                                  Cmdline,
  110.                                  CmdShow);
  111.     
  112.      /* Start the message queue and display the main Window object       */
  113.      /* This invokes the InitInstance() method of the Application object 
  114.       * which calls the InitMainWindow() method to create the main window
  115.       * and calls the Show() method of the main window to display it.    */  
  116.  
  117.  
  118.      MyApplication.Run();
  119.  
  120.      return(MyApplication.Status);
  121.  
  122.    }
  123.  
  124. /*************************************************************************/
  125. /*                                                                       */
  126. /* Member fuctions for the TMyAppObject class, a descendent of the       */
  127. /* OWL TApplication class.  Each OWL program has a single application    */
  128. /* object that handles instance initialization and cleanup, and drives   */
  129. /* the program's message loop.                                           */
  130. /*                                                                       */
  131. /*************************************************************************/
  132.                    
  133.    /*--------------------------------------------------------------------*/
  134.    /* TMyAppObject::InitMainWindow member function                       */
  135.    /* The InitMainWindow function is called by the application's Run()   */
  136.    /* member function.  It creates the application's main window object  */
  137.    /*--------------------------------------------------------------------*/
  138.  
  139.    void TMyAppObject::InitMainWindow()
  140.    {
  141.      /* Instantiate a new Window object derived from OWLs TWindow object 
  142.         and save the handle in the MainWindow data member of the Application
  143.         object                                                          */
  144.       
  145.      MainWindow = new tstctlTWindow(
  146.                       NULL,   /* No parent                               */
  147.                       "Test New Controls");
  148.  
  149.    }
  150.  
  151.  
  152. /*************************************************************************/
  153. /*                                                                       */
  154. /* Member functions of the Window object: tstctlTWindow                  */
  155. /*                                                                       */
  156. /* The tstctlTWindow object is the main window for the                   */
  157. /* application.                                                          */
  158. /*                                                                       */
  159. /*************************************************************************/
  160.  
  161.    /*--------------------------------------------------------------------*/
  162.    /* tstctlTWindow object Constructor                                   */
  163.    /* The constructor is called by C++ whenever an object is created     */
  164.    /* It handles initialization of the object.                           */
  165.    /*--------------------------------------------------------------------*/
  166.  
  167.    tstctlTWindow::tstctlTWindow(
  168.            PTWindowsObject AParent, LPSTR ATitle)
  169.            : TWindow(AParent, ATitle)          /* Base Constructor       */
  170.    {                                                                 
  171.      /* Set the creation attributes for the Window Object                */
  172.      Attr.Style  = 
  173.                    WS_SYSMENU      |      /* Add system menu box         */
  174.                    WS_MINIMIZEBOX  |      /* Add minimize box            */
  175.                    WS_MAXIMIZEBOX  |      /* Add maximize box            */
  176.                    WS_THICKFRAME   |      /* thick sizeable frame        */
  177.                    WS_CAPTION;
  178.      /* Set the Menu attribute of the Window Object.                     */
  179.      AssignMenu("TSTCTL");
  180.      /* Create a device independant size and location                    */
  181.      long  nWndunits = GetDialogBaseUnits();
  182.      int   nWndx = LOWORD(nWndunits);
  183.      int   nWndy = HIWORD(nWndunits);
  184.      int   nX = ((5 * nWndx) / 4);
  185.      int   nY = ((34 * nWndy) / 8);
  186.      int   nWidth = ((206 * nWndx) / 4);
  187.      int   nHeight = ((163 * nWndy) / 8);
  188.  
  189.      /* Set the size and location of the window object                   */
  190.      Attr.X = nX;
  191.      Attr.Y = nY;
  192.      Attr.W = nWidth;
  193.      Attr.H = nHeight;
  194.  
  195.      //add child controls
  196.      //new TUty3DEdit(this, 101, "Edit me", 20, 20, 110, 40, 0, FALSE);
  197.  
  198.      CwCreateClientControls(this);
  199.        
  200.      EnableKBHandler();
  201.      }
  202.   
  203.    /*--------------------------------------------------------------------*/
  204.    /* GetWindowClass() member function                                   */
  205.    /*                                                                    */
  206.    /* This method is called before the window class is registered.  It   */
  207.    /* should set any parameters in the WNDCLASS structure that apply to  */
  208.    /* the tstctlTWindow class                                            */
  209.    /*--------------------------------------------------------------------*/
  210.  
  211.    void tstctlTWindow::GetWindowClass(WNDCLASS _FAR &AWndClass)
  212.    {
  213.  
  214.      /* Call the default method to create WNDCLASS structure with defaults*/
  215.      TWindow::GetWindowClass(AWndClass);
  216.    
  217.      /* Set Registration specific attributes here.                         */
  218.  
  219.      AWndClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  220.    };
  221.  
  222.     /*-------------------------------------------------------------------*/
  223.     /* SetupWindow() member function                                     */
  224.     /* This method is called after the interface element is created. OWL */
  225.     /* invokes it from its WM_CREATE message response member function.   */
  226.     /*-------------------------------------------------------------------*/
  227.  
  228.     void tstctlTWindow::SetupWindow()
  229.     {
  230.      
  231.      /* Call the default */
  232.      TWindow::SetupWindow();
  233.  
  234.      pList->AddString("Item 1");
  235.      pList->AddString("Item 2");
  236.      pList->AddString("Item 3");
  237.      pList->AddString("Item 4");
  238.      pList->AddString("Item 5");
  239.      pList->AddString("Item 6");
  240.      pList->AddString("Item 7");
  241.      pList->AddString("Item 8");
  242.      pList->AddString("Item 9");
  243.     }
  244.  
  245.    /*--------------------------------------------------------------------*/
  246.    /* CMMethod_IDM_DIALOG() command response member function             */
  247.    /* Called when the user selects the IDM_DIALOG                        */
  248.    /* menu item                                                          */
  249.    /*--------------------------------------------------------------------*/
  250.  
  251.    void tstctlTWindow:: CMMethod_IDM_DIALOG(RTMessage Msg)
  252.    {
  253.   
  254.      /* Execute the Modal Dialog: testTDialog  Object.    */
  255.      GetModule()->ExecDialog(
  256.                      new testTDialog(this, IDLG_TEST));
  257.      UNREFERENCED_PARAMETER(Msg);
  258.    }
  259.  
  260. void tstctlTWindow::WMCtlColor(RTMessage msg)
  261. {
  262.    HBRUSH hbrush;
  263.  
  264.     hbrush = UtyCtlWMCtlColor(msg.Message,
  265.                              msg.WParam,
  266.                              msg.LParam);
  267.  
  268.     if (hbrush != (HBRUSH)FALSE)
  269.        msg.Result = (LRESULT)hbrush;
  270.    else
  271.       DefWndProc(msg);
  272.       
  273.  
  274. }
  275.  
  276. /*******************************************************************
  277.     Function: CwCreateClientControls(
  278.  
  279.        Description:
  280.  
  281. ********************************************************************/
  282.  
  283.    void  tstctlTWindow::CwCreateClientControls(PTWindowsObject parent)
  284.    {
  285.      int  nCyscroll;                   /* Height of the scroll Arrow     */
  286.      long  DlgUnits;                   /* Structure to store Dialog units*/
  287.     
  288.      #define DlgToWinX(x)   ((x * LOWORD(DlgUnits)) / 4)  /*   x modulo  */
  289.      #define DlgToWinY(y)   ((y * HIWORD(DlgUnits)) / 8)  /*   y modulo  */
  290.      nCyscroll = 0;
  291.       
  292.      /* Get the dialog units by querying the system                      */
  293.      DlgUnits = GetDialogBaseUnits();
  294.  
  295.      /* Create all the Controls as children                              */
  296.      PTWindow control;
  297.  
  298.      control =
  299.      new TUty3DStatic(parent, -1,
  300.             "Test Controls with SUTY3D.DLL",
  301.             DlgToWinX(46),                        /* x position          */
  302.             DlgToWinY(4)+nCyscroll,               /* y position          */
  303.             DlgToWinX(108),                       /* width               */
  304.             DlgToWinY(8),                         /* height              */
  305.             80);
  306.  
  307.      //control->Attr.Style |= 
  308.      //      SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP;
  309.                          
  310.    
  311.      pList =
  312.      new TUty3DListBox(parent, 101,
  313.             DlgToWinX(8),                         /* x position          */
  314.             DlgToWinY(26)+nCyscroll,              /* y position          */
  315.             DlgToWinX(49),                        /* width               */
  316.             DlgToWinY(33));                       /* height              */
  317.  
  318.      //pList->Attr.Style |= 
  319.      //      LBS_NOTIFY | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL;
  320.                          
  321.    
  322.      control =
  323.      new TUty3DComboBox(parent, 102,
  324.             DlgToWinX(66),                        /* x position          */
  325.             DlgToWinY(26)+nCyscroll,              /* y position          */
  326.             DlgToWinX(31),                        /* width               */
  327.             DlgToWinY(33),                        /* height              */
  328.             CBS_SIMPLE, 80);
  329.  
  330.      control->Attr.Style |= 
  331.            CBS_SIMPLE | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  332.                          
  333.    
  334.      control =
  335.      new TUty3DComboBox(parent, 103,
  336.             DlgToWinX(106),                       /* x position          */
  337.             DlgToWinY(26)+nCyscroll,              /* y position          */
  338.             DlgToWinX(30),                        /* width               */
  339.             DlgToWinY(33),                        /* height              */
  340.             CBS_DROPDOWN, 80);
  341.  
  342.      control->Attr.Style |= 
  343.            CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  344.                          
  345.    
  346.      control =
  347.      new TUty3DComboBox(parent, 104,
  348.             DlgToWinX(145),                       /* x position          */
  349.             DlgToWinY(26)+nCyscroll,              /* y position          */
  350.             DlgToWinX(36),                        /* width               */
  351.             DlgToWinY(33),                        /* height              */
  352.             CBS_DROPDOWN, 80);
  353.  
  354.      control->Attr.Style |= 
  355.            CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  356.                          
  357.    
  358.      control =
  359.      new TUty3DGroupBox(parent, 105,
  360.             "Check Boxes",
  361.             DlgToWinX(7),                         /* x position          */
  362.             DlgToWinY(70)+nCyscroll,              /* y position          */
  363.             DlgToWinX(75),                        /* width               */
  364.             DlgToWinY(42),                        /* height              */
  365.             NULL);
  366.  
  367.      //control->Attr.Style |= 
  368.      //      BS_GROUPBOX | WS_CHILD | WS_VISIBLE;
  369.                          
  370.    
  371.      control =
  372.      new TUty3DCheckBox(parent, 106,
  373.             "Text",
  374.             DlgToWinX(20),                        /* x position          */
  375.             DlgToWinY(83)+nCyscroll,              /* y position          */
  376.             DlgToWinX(28),                        /* width               */
  377.             DlgToWinY(12),                        /* height              */
  378.             NULL);
  379.  
  380.  
  381.      //control->Attr.Style |= 
  382.      //      BS_CHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  383.                          
  384.    
  385.      control =
  386.      new TUty3DCheckBox(parent, 107,
  387.             "Text",
  388.             DlgToWinX(20),                        /* x position          */
  389.             DlgToWinY(96)+nCyscroll,              /* y position          */
  390.             DlgToWinX(28),                        /* width               */
  391.             DlgToWinY(12),                        /* height              */
  392.             NULL);
  393.      
  394.      //control->Attr.Style |= 
  395.      //      BS_CHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  396.                          
  397.    
  398.      control =
  399.      new TUty3DGroupBox(parent, 108,
  400.             "Radios",
  401.             DlgToWinX(94),                        /* x position          */
  402.             DlgToWinY(70)+nCyscroll,              /* y position          */
  403.             DlgToWinX(75),                        /* width               */
  404.             DlgToWinY(42),                        /* height              */
  405.             NULL);
  406.  
  407.      //control->Attr.Style |= 
  408.      //      BS_GROUPBOX | WS_CHILD | WS_VISIBLE;
  409.                          
  410.    
  411.      control =
  412.      new TUty3DRadioButton(parent,  109,
  413.             "Radio",
  414.             DlgToWinX(105),                       /* x position          */
  415.             DlgToWinY(81)+nCyscroll,              /* y position          */
  416.             DlgToWinX(28),                        /* width               */
  417.             DlgToWinY(12),                        /* height              */
  418.             NULL);
  419.   
  420.      
  421.      //control->Attr.Style |= 
  422.      //      BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  423.                          
  424.    
  425.      control =
  426.      new TUty3DRadioButton(parent,  110,
  427.             "Radio",
  428.             DlgToWinX(105),                       /* x position          */
  429.             DlgToWinY(96)+nCyscroll,              /* y position          */
  430.             DlgToWinX(28),                        /* width               */
  431.             DlgToWinY(12),                        /* height              */
  432.             NULL);
  433.   
  434.      
  435.      //control->Attr.Style |= 
  436.      //      BS_RADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP;
  437.                          
  438.    };
  439.  
  440.  
  441.  
  442.  
  443. /*************************************************************************/
  444. /*                                                                       */
  445. /* Member functions For Dialog object testTDialog                        */
  446. /*                                                                       */
  447. /* The Dialog object displays a modal or modeless dialog box.            */
  448. /*************************************************************************/
  449.     
  450.    /* Constructor  */
  451.    testTDialog::testTDialog(
  452.            PTWindowsObject AParent, int ResourceID)
  453.            : TDialog(AParent, ResourceID)          /* Parent Constructor */
  454.    {
  455.    }
  456.  
  457.    /*--------------------------------------------------------------------*/
  458.    /* SetupWindow method for the testTDialog                             */
  459.    /*                                                                    */
  460.    /* Called after the dialog's window is created, but before it is      */
  461.    /* displayed.  This is similar to the TWindow's SetupWindow method    */
  462.    /* but is called in response to the WM_INITDIALOG message.            */
  463.    /*--------------------------------------------------------------------*/
  464.  
  465.    void testTDialog::SetupWindow()
  466.    {
  467.      /* Let the default processing be done */
  468.      /* Any special processing that has to be done on the control object 
  469.         has to be done here.                                             */
  470.      TDialog::SetupWindow();
  471.  
  472.      /* Center the Dialog On the Client Area of the Parent.              */
  473.      /*
  474.      RECT swp, rParent;
  475.      POINT pt;
  476.      GetWindowRect(HWindow, &swp);
  477.      GetClientRect(Parent->HWindow, &rParent);
  478.      int nWidth = swp.right - swp.left;
  479.      int nHeight = swp.bottom - swp.top;
  480.      pt.x = (rParent.right - rParent.left) / 2;
  481.      pt.y = (rParent.bottom - rParent.top) / 2;
  482.      ClientToScreen(Parent->HWindow, &pt);
  483.      pt.x = pt.x - (nWidth / 2);
  484.      pt.y = pt.y - (nHeight / 2);
  485.      MoveWindow(HWindow, pt.x, pt.y, nWidth, nHeight, FALSE);
  486.      */
  487.    }
  488.  
  489.  
  490.    /*--------------------------------------------------------------------*/
  491.    /* Ok() - command response member function.                           */
  492.    /*                                                                    */
  493.    /* Called when the user presses the "OK" button.                      */
  494.    /*--------------------------------------------------------------------*/
  495.    void testTDialog::Ok(RTMessage Msg)
  496.    {
  497.      switch (Msg.LP.Hi)
  498.       {
  499.        case BN_CLICKED:
  500.             Destroy(TRUE);
  501.  
  502.             break;    
  503.       }
  504.    }
  505.  
  506. void testTDialog::FileOpen(RTMessage Msg)
  507. {
  508.    switch (Msg.LP.Hi)
  509.    {
  510.       case BN_CLICKED:
  511.       {
  512.         
  513.           OPENFILENAME ofnTemp;
  514.          DWORD Errval;    // Error value
  515.           char buf[5];    // Error buffer
  516.           char Errstr[50]="GetOpenFileName returned Error #";
  517.  
  518.           
  519.          char szName[256];
  520.           char szTemp[] = "All Files (*.*)\0*.*\0Text Files (*.txt)\0*.txt\0";
  521.          *szName = '\0';
  522.           ofnTemp.lStructSize = sizeof( OPENFILENAME );
  523.           ofnTemp.hwndOwner = HWindow;    
  524.           ofnTemp.hInstance = UtyCtlGetInstance();  //get instance of the dll for the template
  525.           ofnTemp.lpstrFilter = (LPSTR)szTemp;
  526.           ofnTemp.lpstrCustomFilter = NULL;
  527.           ofnTemp.nMaxCustFilter = 0;
  528.           ofnTemp.nFilterIndex = 1;
  529.           ofnTemp.lpstrFile = (LPSTR)szName;
  530.           ofnTemp.nMaxFile = sizeof( szName );
  531.           ofnTemp.lpstrFileTitle = NULL;
  532.           ofnTemp.nMaxFileTitle = 0;
  533.           ofnTemp.lpstrInitialDir = NULL;
  534.           ofnTemp.lpstrTitle = "3D OpenFile";
  535.           ofnTemp.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY
  536.                         | OFN_PATHMUSTEXIST |OFN_ENABLETEMPLATE;
  537.                         //turn on template flag
  538.           ofnTemp.nFileOffset = 0;
  539.           ofnTemp.nFileExtension = 0;
  540.           ofnTemp.lpstrDefExt = "*";
  541.           ofnTemp.lCustData = NULL;
  542.           ofnTemp.lpfnHook = NULL;
  543.           ofnTemp.lpTemplateName = UtyCtlGetTemplate(UTY3DTEMP_OPENSAVE);
  544.                                   //gives the tempate name in the 3d dll
  545.                                   //see uty25001.h for other #defines
  546.  
  547.           if(GetOpenFileName( &ofnTemp ) != TRUE)
  548.           {
  549.               Errval=CommDlgExtendedError();
  550.               if(Errval!=0)    // 0 value means user selected Cancel
  551.               {
  552.                   sprintf(buf,"%ld",Errval);
  553.                   strcat(Errstr,buf);
  554.                   MessageBox(HWindow,Errstr,"WARNING",MB_OK|MB_ICONSTOP);
  555.               }
  556.  
  557.           }
  558.  
  559.       }
  560.  
  561.    }  
  562.      
  563. }
  564.  
  565.  
  566.       
  567.